package com.xana.acg.mikomiko.media;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.util.AttributeSet;
import android.view.View;

import com.xana.acg.com.view.LoadingView;
import com.xana.acg.mikomiko.App;
import com.xana.acg.mikomiko.R;

import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

/**
 * 根据视频宽高自适应全屏方向
 */
public class TiktokVideoView extends JzvdStd {

    public TiktokVideoView(Context context) {
        super(context);
    }

    public TiktokVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    LoadingView loadingView;
    @Override
    public void init(Context context) {
        super.init(context);
        loadingProgressBar.setVisibility(GONE);
        loadingView = findViewById(R.id.loadingView);
        loadingView.start();
    }

    @Override
    public void onVideoSizeChanged(int width, int height) {
        super.onVideoSizeChanged(width, height);
        if (width > 0 && height > 0) {
            if (height > width) {
                Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            } else {
                Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            }
        }
    }

    @Override
    public int getLayoutId() {
        return R.layout.view_tiktok_video;
    }

    @Override
    public void reset() {
        super.reset();
        Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
        Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    }

    @Override
    public void onCompletion() {
        super.onCompletion();
        App.showToast("完成");
        clickStart();
    }

    @Override
    public void setAllControlsVisiblity(int topCon, int bottomCon, int startBtn, int loadingPro, int posterImg, int bottomPro, int retryLayout) {
        super.setAllControlsVisiblity(topCon, bottomCon, startBtn, loadingPro, posterImg, bottomPro, retryLayout);
        loadingProgressBar.setVisibility(GONE);
        loadingView.setVisibility(loadingPro);
    }

    @Override
    public void onPrepared() {
        super.onPrepared();
    }
}
